home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / Xconq 7.0d16 / Xconq 7.0d16 src / src / task.c < prev    next >
Encoding:
Text File  |  1993-12-20  |  40.6 KB  |  133 lines  |  [TEXT/MPS ]

  1.             continue;
  2.             }
  3.         }
  4.         }
  5.         return TASK_FAILED;
  6.     }
  7.     if (valid(check_move_action(unit, unit, tx, ty, unit->z))) {
  8.         /* Moving into an empty hex. */
  9.         prep_move_action(unit, unit, tx, ty, unit->z);
  10.         return TASK_PREPPED_ACTION;
  11.     } else {
  12.         return TASK_FAILED;
  13.     }
  14.     break;
  15.       default:
  16.     /* Still some distance away, pick a way to go. */
  17.         /* If on mobile transport, let it handle things. */
  18.         if (unit->transport != NULL
  19.             && mobile(unit->transport->type)
  20.             /* and the transport is not blocked */
  21.             && flip_coin()) {
  22.             unit->plan->reserve = TRUE;
  23.             return TASK_INCOMPLETE;
  24.         }
  25.     numdirs = choose_move_dirs(unit, tx, ty, TRUE,
  26.                    plausible_move_dir, sort_directions, dirs);
  27.     for (i = 0; i < numdirs; ++i) {
  28.         point_in_dir(unit->x, unit->y, dirs[i], &nx, &ny);
  29.         for_all_stack(nx, ny, unit2) {
  30.         if (can_occupy(unit, unit2)) {
  31.             if (valid(check_enter_action(unit, unit, unit2))) {
  32.             prep_enter_action(unit, unit, unit2);
  33.             /* We (probably) made forward progress, so reopen choice of dirs. */
  34.             task->args[3] = eitherway;
  35.             return TASK_PREPPED_ACTION;
  36.             } else {
  37.             continue;
  38.             }
  39.         } else if (unit2->side != unit->side) {
  40.             if (unit->occupant) {
  41.                 /* More important to find a way through. */
  42.                 continue;
  43.             } else {
  44.                 /* This will encourage some re-evaluation. */
  45.                 return TASK_FAILED;
  46.             }
  47. #if 0 /* the following is rarely a good idea */
  48.             if (valid(check_attack_action(unit, unit, unit2, 100))) {
  49.             prep_attack_action(unit, unit, unit2, 100);
  50.             /* We (probably) made forward progress, so reopen choice of dirs. */
  51.             task->args[3] = eitherway;
  52.             return TASK_PREPPED_ACTION;
  53.             } else {
  54.             continue;
  55.             }
  56. #endif
  57.         }
  58.         }
  59.         if (valid(check_move_action(unit, unit, nx, ny, unit->z))) {
  60.         prep_move_action(unit, unit, nx, ny, unit->z);
  61.         /* We (probably) made forward progress, so reopen choice of dirs. */
  62.         task->args[3] = eitherway;
  63.         return TASK_PREPPED_ACTION;
  64.         }
  65.     }
  66.     /* Get both right and left non-decreasing dirs. */
  67.     numdirs  = choose_move_dirs(unit, tx, ty, TRUE, NULL, NULL, dirs);
  68.     numdirs2 = choose_move_dirs(unit, tx, ty, FALSE, NULL, NULL, dirs);
  69.     for (i = numdirs; i < numdirs2; ++i) {
  70.       if (plausible_move_dir(unit, dirs[i])) {
  71.         switch (task->args[3]) {
  72.           case eitherway:
  73.         if (i == numdirs) task->args[3] = leftonly /* leftthenright */;
  74.             if (i == numdirs+1) task->args[3] = rightonly /* rightthenleft */;
  75.         break;
  76.           case leftthenright:
  77.         if (i == numdirs) task->args[3] = rightonly;
  78.             if (i == numdirs+1) task->args[3] = rightonly;
  79.             continue;
  80.         break;
  81.           case rightthenleft:
  82.             if (i == numdirs+1) task->args[3] = leftonly;
  83.             continue;
  84.         break;
  85.           case leftonly:
  86.             if (i == numdirs+1) continue;
  87.         break;
  88.           case rightonly:
  89.             if (i == numdirs) continue;
  90.         break;
  91.         }
  92.       } else {
  93.         switch (task->args[3]) {
  94.           case eitherway:
  95.             if (i == numdirs) task->args[3] = rightonly;
  96.                 if (i == numdirs+1) task->args[3] = leftonly;
  97.                 continue;
  98.         break;
  99.           case leftthenright:
  100.             if (i == numdirs) task->args[3] = rightonly;
  101.                 if (i == numdirs+1) task->args[3] = rightonly;
  102.                 continue;
  103.         break;
  104.           case rightthenleft:
  105.                 if (i == numdirs+1) task->args[3] = leftonly;
  106.                 continue;
  107.         break;
  108.           case leftonly:
  109.             if (i == numdirs) return TASK_FAILED;
  110.             if (i == numdirs+1) continue;
  111.         break;
  112.           case rightonly:
  113.             if (i == numdirs) continue;
  114.             if (i == numdirs+1) return TASK_FAILED;
  115.         break;
  116.         }
  117.       }
  118.         point_in_dir(unit->x, unit->y, dirs[i], &nx, &ny);
  119.         for_all_stack(nx, ny, unit2) {
  120.         if (can_occupy(unit, unit2)) {
  121.             if (valid(check_enter_action(unit, unit, unit2))) {
  122.             prep_enter_action(unit, unit, unit2);
  123.             return TASK_PREPPED_ACTION;
  124.             } else {
  125.             continue;
  126.             }
  127.         } else if (unit2->side != unit->side) {
  128.             if (unit->occupant) {
  129.                 /* More important to find a way through. */
  130.                 continue;
  131.             } else {
  132.                 /* This will encourage some re-evaluation. */
  133.                 ret